<template>
	<view class="section group-buy">
		<view class="section-title">
			<text class="title-text">拼团特惠</text>
			<text class="more" @click="navigateToMore">更多 ></text>
		</view>
		<scroll-view scroll-x class="group-scroll">
			<view class="group-card" v-for="(item, index) in groupProducts" :key="index" @click="navigateToDetail(item.id)">
				<image :src="item.logo" mode="aspectFill" class="group-img"></image>
				<view class="group-info">
					<text class="group-name">{{item.name}}</text>
					<view class="group-price-box">
						<text class="group-price">¥{{item.groupPrice}}</text>
						<text class="original-price">¥{{item.price}}</text>
					</view>
					<view class="group-progress">
						<view class="progress-bar">
							<view class="progress-inner" :style="{width: (item.sold/item.stock*100)+'%'}"></view>
						</view>
						<text class="progress-text">已拼{{item.sold}}件</text>
					</view>
					<view class="group-status">
						<text class="status-text">{{item.status === 1 ? '正在拼团' : '即将开始'}}</text>
						<text class="group-count">{{item.groupCount}}人成团</text>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script setup>
import {useData} from "/common/useData";

// 获取拼团商品数据
const {modelData:groupProducts}=useData("/product/search",{size:5})

// 跳转到详情页
const navigateToDetail = (id) => {
	uni.navigateTo({
		url: `/pages/detail/view?id=${id}`
	})
}

// 跳转到更多页面
const navigateToMore = () => {
	uni.navigateTo({
		url: `/pages/product-list/group`
	})
}
</script>

<style>
.section {
	background-color: #FFFFFF;
	padding: 20rpx;
	margin-bottom: 20rpx;
}

.section-title {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 20rpx;
}

.title-text {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
	padding-left: 20rpx;
	border-left: 8rpx solid #D02B29;
}

.more {
	font-size: 24rpx;
	color: #999;
}

.group-scroll {
	white-space: nowrap;
}

.group-card {
	display: inline-block;
	width: 300rpx;
	margin-right: 20rpx;
	background-color: #F5F5F5;
	border-radius: 10rpx;
	overflow: hidden;
}

.group-img {
	width: 300rpx;
	height: 300rpx;
}

.group-info {
	padding: 10rpx;
}

.group-name {
	font-size: 26rpx;
	color: #333;
	display: block;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	margin-bottom: 8rpx;
}

.group-price-box {
	display: flex;
	align-items: baseline;
	margin-bottom: 8rpx;
}

.group-price {
	font-size: 32rpx;
	color: #D02B29;
	font-weight: bold;
	margin-right: 10rpx;
}

.original-price {
	font-size: 24rpx;
	color: #999;
	text-decoration: line-through;
}

.group-progress {
	display: flex;
	align-items: center;
	margin-bottom: 8rpx;
}

.progress-bar {
	flex: 1;
	height: 6rpx;
	background-color: #EEEEEE;
	border-radius: 3rpx;
	margin-right: 10rpx;
	overflow: hidden;
}

.progress-inner {
	height: 100%;
	background-color: #D02B29;
	border-radius: 3rpx;
}

.progress-text {
	font-size: 22rpx;
	color: #999;
}

.group-status {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.status-text {
	font-size: 24rpx;
	color: #D02B29;
}

.group-count {
	font-size: 24rpx;
	color: #666;
}
</style>
